package com.qf.student.service.impl;

import com.qf.student.dao.AdminMapper;
import com.qf.student.dao.TeacherMapper;
import com.qf.student.entity.Admin;
import com.qf.student.entity.Department;
import com.qf.student.dao.DepartmentMapper;
import com.qf.student.entity.Teacher;
import com.qf.student.response.R;
import com.qf.student.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-11-21
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public R getDepartmentById(Integer teacherId, Integer userId) {
        Teacher teacher = teacherMapper.selectById(teacherId);
        if (teacher == null) {
            return R.createFAIL("教师信息有误");
        }

        Admin admin = adminMapper.selectById(userId);
        if (admin == null) {
            return R.createFAIL("登录信息有误，请重新登录");
        }

        Department department = departmentMapper.getDepartmentByIdb(teacherId);
        return R.createSuccess(department);
    }

}
